//
//  LGRecipeMedicineHeader.m
//  XieHeHeartDisease
//
//  Created by 1234 on 2024/3/4.
//

#import "LGRecipeMedicineHeader.h"

@interface LGRecipeMedicineHeader()

/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UIButton *platesButton;

@end

@implementation LGRecipeMedicineHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
    CGFloat topMargin = (title.length>0)?viewPix(47):viewPix(16);
    [self.dateLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(topMargin);
    }];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.dateLabel.text = [NSString stringWithFormat:@"%@ %@",dataDic[@"date_str"],dataDic[@"name"]];
}

-(void)platesButtonAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(platesRecipeAction:)]){
        [self.delegate platesRecipeAction:LGNSString(self.dataDic[@"prescription_id"])];
    }
}

-(void)createSubView{
    [self addSubview:self.titleLabel];
    [self addSubview:self.dateLabel];
//    [self addSubview:self.platesButton];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(viewPix(16));
        make.left.equalTo(self).offset(viewPix(18));
        make.right.equalTo(self).offset(-viewPix(16));
    }];
//    [self.platesButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self).offset(-viewPix(16));
//        make.centerY.equalTo(self.dateLabel);
//        make.width.equalTo(@(viewPix(80)));
//        make.height.equalTo(@(viewPix(28)));
//    }];
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(18), viewPix(16), Screen_W-viewPix(36), viewPix(21));
    }
    return _titleLabel;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _dateLabel;
}

-(UIButton *)platesButton{
    if(!_platesButton){
        _platesButton = [UIButton buttonWithTitle:@"一键复制" titleFont:LGFont(14) normalColor:@"#FFFFFF" selectColor:@"#FFFFFF"];
        _platesButton.backgroundColor = [UIColor colorWithString:kThemeColor];
        _platesButton.cornerRidus = viewPix(14);
        [_platesButton addTarget:self action:@selector(platesButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _platesButton;
}

@end
